<template>
    <div>
        <rui-page :defines="defines" v-show="isShow">
            <rui-query :label-width="180"
                       ref="searchForm"
                       :query="queryData"
                       :query-rows="searchFormOptions"
            >
            </rui-query>
            <Row>
                <Alert show-icon>
                    已选择 <span class="select-count">{{selectCount}}</span> 项
                    <a class="select-clear" @click="clearSelectAll">清空</a>
                </Alert>
            </Row>
            <rui-table
                :defineId="'productApproveTaskDefine'"
                :fixedLeft="['action']"
                :showIndex="false"
                :select="false"
                :columns="columns"
                :slots="[{key:'action',slot:'action'}]"
                @loadDatas="queryData"
                @on-selection-change="changeSelect"
                ref-query="searchForm"
                ref="taskTable"
            >
                <template slot="action" slot-scope="{ row }">
                    <div>
                        <Button type="primary" size="small" @click="edit(row)">审批</Button>
                    </div>
                </template>

            </rui-table>
        </rui-page>
        <countersignApproval v-if="launchShow" @backPage="backPage" :parms="parms"/>
    </div>
</template>
<script>
    import productApproveTaskDefine from "./defines/product-approve-task-launch-define";
    import {
        queryApproveTaskLaunchList
    } from "@/projects/afs-core-business/api/afs-product/approve/approveTask";

    import countersignApproval from "@/projects/afs-core-business/pages/product/product-launch/countersignApproval.vue";

    export default {
        name: "approve-task",
        components: {
            countersignApproval,
        },
        data() {
            return {
                afsFlowKey: this.afs.getPageParams(this).afsFlowKey,
                taskNodeId: this.afs.getPageParams(this).taskNodeId,
                isShow: true,
                launchShow: false,
                searchFormOptions: [
                    {
                        defineId: "productApproveTaskDefine", span: 24, fields: ["onlineNumber",'onlineName']
                    },
                ],
                columns: [
                    'action', 'onlineNumber', 'onlineName','createDate'
                ],
                selectCount: 0,
                parms: {},
            };
        },
        computed: {
            defines() {
                return [
                    {
                        id: "productApproveTaskDefine",
                        fields: productApproveTaskDefine
                    }
                ];
            }
        },
        mounted() {
            this.refresh();
        },
        methods: {
            queryData(queryData) {
                queryData["condition"]["afsFlowKey"] = this.afsFlowKey;
                queryData["condition"]["taskNodeId"] = this.taskNodeId;
                console.info("queryData上线查询:"+JSON.stringify(queryData));
                queryApproveTaskLaunchList(queryData).then(res => {
                    if (res.code === "0000") {
                        let {records, total} = res.data;
                        this.$refs.taskTable.updateTableData(records, total);
                    }
                });
            },
            refresh() {
                this.$refs['taskTable'].reloadData();
                this.clearSelectAll();
            },
            clearSelectAll() {
                this.$refs.taskTable.getTable().selectAll(false);
            },
            changeSelect(e) {
                this.selectList = e;
                this.selectCount = e.length;
            },
            edit(v) {
                this.launchShow = true;
                this.isShow = false;
                console.info(v);
                var taskMemo = (v["taskMemo"]);
                var result = eval('(' + taskMemo + ')');
                console.info(result);
                this.parms = {planId: v.id, taskNodeId: result["judge"],stageId: v.id};
            },
            backPage() {
                this.isShow = true;
                this.launchShow = false;
                this.refresh();
            },
        }
    };
</script>
